package WebserviceChecker;

import java.io.File;
import java.util.HashMap;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import DatabaseManaging.DatabaseChecker;
import DatabaseManaging.JdbcChannelsDao;
import DatabaseManaging.JdbcLanguageDao;
import DatabaseManaging.LanguageChannelDatabaseChecker;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
					//Read Web Service Method //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public class ChannelLanguageChecker extends WbChecker{
	private String parameter;
	
	public String getParameter() {
		return parameter;
	}
	public void setParameter(String parameter) {
		this.parameter = parameter;
	}
	public ChannelLanguageChecker(){
		super();
	}
	public ChannelLanguageChecker(DatabaseChecker dbchecker){
		super(dbchecker);
	}
	@Override
	public HashMap<String, String>  readWebService(String[] record,
			HashMap<String, String> ht)  {
		String stbuffer="";
		ht.put("e",null);
		ht = webReader.readXml("", "", record[0], parameter);
		if (ht.get("e") == null) {
			stbuffer = writeDefaultLine(ht.get("d"), record[0]);
		}else{
			stbuffer = writeDefaultLine(record[0], "");
		}
		ht.put("value", stbuffer);
		return ht;
	}
	
	private String writeDefaultLine(String value,String languageAbbr){
		String lang="\t"+value+"\t"+languageAbbr;
		return lang;
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
						// CheckNotRepeatedBaseline Methods//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public String generateReg(String[] recordToAdd, String abbr) {
		String reg="";
		reg = writeDefaultLine(recordToAdd[1], abbr);
		return reg;
	}
	
	@Override
	public boolean areEquals(String string, String string2) {
		boolean result=false;
		String [] record1=string.split("\t");
		String [] record2=string2.split("\t");
		//System.out.println(record1[1]+"------------"+record2[1]);
		if(record1[1].equals(record2[1])){
			result=true;
		}
		return result;		
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// CheckNotRepeatedBaseline Methods//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public static void main(String args[]){
	    ApplicationContext context = new ClassPathXmlApplicationContext("application-context-persist.xml");
	    JdbcLanguageDao dao=(JdbcLanguageDao) context.getBean("JdbcLanguagesDao");
	    LanguageChannelDatabaseChecker langchecker=new LanguageChannelDatabaseChecker();
	    langchecker.setJdbc(dao);
		ChannelLanguageChecker pdChecker=new ChannelLanguageChecker(langchecker);
		pdChecker.setParameter("languages");
		System.out.println("Write the File input");
		File finput=new File(args[0]);
		System.out.println("Write the File Output");
		System.out.println("Write the File Not Found");
		File foutNotFound=new File(args[2]);

	    JdbcChannelsDao dao2=(JdbcChannelsDao) context.getBean("JdbcChannelsDao");
	    LanguageChannelDatabaseChecker channelChecker=new LanguageChannelDatabaseChecker();
	    channelChecker.setJdbc(dao2);
		ChannelLanguageChecker pdCheckerChannel=new ChannelLanguageChecker(channelChecker);
		pdCheckerChannel.setParameter("channels");
		System.out.println("Write the File input");
		File finput2=new File(args[3]);
		System.out.println("Write the File Output");
		System.out.println("Write the File Not Found");
		File foutNotFound2=new File(args[5]);
		
		System.out.println("------------------------------Languages----------------------------------------");
		//pdChecker.checkWebService(finput, foutNotFound);
		System.out.println("------------------------------Channel----------------------------------------");
		//pdCheckerChannel.checkWebService(finput2, foutNotFound2);

		
	}

}
